#include <Arduino.h>
#include <DigitalTube.h>

int digitalRead(uint32_t ulPin) {
    PinName pn = digitalPinToPinName(ulPin);
    GPIO_TypeDef *GPIOx = get_GPIO_Port(STM_PORT(pn));
    uint32_t PinMask = STM_LL_GPIO_PIN(pn);
    uint32_t GPIO_Pin = (PinMask >> GPIO_PIN_MASK_POS) & 0x0000FFFFU;    
    return (HAL_GPIO_ReadPin(GPIOx, GPIO_Pin) == GPIO_PIN_RESET) ? LOW : HIGH;
}

const uint8_t digital_tube_pos_pins[8] = {PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8};
const uint8_t digital_tube_neg_pins[3] = {PA13, PA14, PA15};

DigitalTube digital_tube(digital_tube_pos_pins, digital_tube_neg_pins);

#define BUTTON_PIN PB1


void lit_frame(const char* str) {
    for (uint8_t i = 0; str[i] != '\0'; ++i) {
        digital_tube.lit(i + 1, str[i]);
        delay(3);
    }
}

void press_callback_function() {
    lit_frame("2025.7.4");
}

void not_press_callback_function() {
    lit_frame("5201314");
}

bool button_is_pressed() {
    return digitalRead(BUTTON_PIN) == LOW ? true : false;
}


void setup() {
    digital_tube.begin();
    pinMode(BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
    digitalRead(BUTTON_PIN) == LOW ? press_callback_function() : not_press_callback_function();
}
